<?php
namespace app\admin\logic;
use think\Facade\Db;
use app\common\Apiv;
use app\common\Util;
/**
 * @Author: K.EL
 * @Date:   2020-07-23 14:03:43
 * @Last Modified by:   K.EL
 * @Last Modified time: 2020-07-24 13:41:12
 */
class ConfLogic{
	static function getLists(){
		$title = input('title', '');
		$status = input('status', '');
		$pageSize = input('size', 10);
		$obj = Db::name('sys_config')->field('*,CAST(status AS CHAR) as status');
		if($title){
			$obj->where('title','like','%'.$title.'%');
		}
		if($status){
			$obj->where('status', $status);
		}else{
			$obj->where('status','exp','>0');
		}
		$lists = $obj->order('id desc')->paginate($pageSize);
		return Apiv::result(1,0,'OK', $lists);
	}


	static function getInfo(){
		$id = input('id', 0);
		$info = Db::name('sys_config')->where('id', $id)->find();
		return Apiv::result(1,0,'信息获取成功', $info);
	}
	
	static function add(){
		$data = [];
		$data['title'] = input('title', '');
		$data['key'] = input('key', '');
		$data['value'] = input('value','');
		$data['status'] = input('status', 1);
		$data['remark'] = input('remark', '');
		$data['add_time'] = date('Y-m-d h:i:s');
		Db::name('sys_config')->insert($data);
		return Apiv::result(1,0,'新增成功');
	}

	static function edit(){
		$data = [];
		$data['title'] = input('title', '');
		$data['key'] = input('key', '');
		$data['value'] = input('value','');
		$data['status'] = input('status', 1);
		$data['remark'] = input('remark', '');
		// $data['add_time'] = date('Y-m-d h:i:s');
		$id = input('id', 0);
		Db::name('sys_config')->where('id', $id)->update($data);
		return Apiv::result(1,0,'编辑成功');
	}
}